package com.guigu.tms.customer.controller;

import com.guigu.tms.commons.user.entity.AddressBook;
import com.guigu.tms.commons.user.feign.AddressBookFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("addressBook")
public class AddressController {

    @Autowired
    private AddressBookFeignClient addressBookFeignClient;

    @GetMapping("getAddressBook")
    List<AddressBook> getAddressBook(String memberId){
        return addressBookFeignClient.getAddressBook(memberId);
    }

    @GetMapping("getDefaultAddressBook")
    public AddressBook getDefaultAddressBook(@RequestParam String userId){
        AddressBook defaultAddressBook = addressBookFeignClient.getDefaultAddressBook(userId);
        return defaultAddressBook;
    }

    @PostMapping("addAddressBook")
    public boolean addAddressBook(@RequestBody AddressBook addressBook){
        System.out.println(addressBook);
        return addressBookFeignClient.addAddressBook(addressBook);
    }

    @PutMapping("updateAddressBook")
    public boolean updateAddressBook(@RequestBody AddressBook addressBook){
       return addressBookFeignClient.updateAddressBook(addressBook);
    }


    @DeleteMapping("deleteAddressBook/{id}")
    public boolean deleteAddressBook(@PathVariable("id") String id){
        return addressBookFeignClient.deleteAddressBook(id);
    }

    @PutMapping("setDefaultAddressBook")
    public boolean setDefaultAddressBook(String userId,String id){
        System.out.println(userId);
        return addressBookFeignClient.setDefaultAddressBook(userId, id);
    }

    @GetMapping("getAddressBookById")
    public AddressBook getAddressBookById(String id){
        return addressBookFeignClient.getAddressBookById(id);
    }

}
